<?php
/**
 * Created by PhpStorm.
 * User: issuser
 * Date: 2017/6/30
 * Time: 下午6:32
 */
require_once "../src/autoload.php";
require_once "../public/ChatApi.php";
require_once "../public/CollectApi.php";

use LeanCloud\Client;
use LeanCloud\Engine\LeanEngine;
use LeanCloud\Engine\Cloud;
use LeanCloud\Storage\CookieStorage;

Client::initialize(
    getenv("LC_APP_ID"),
    getenv("LC_APP_KEY"),
    getenv("LC_APP_MASTER_KEY")
);
Client::setStorage(new CookieStorage());
Client::useRegion("CN");


Cloud::define("collectHome", function (){

    CollectApi::collectHome();
});



//收到消息
Cloud::define("_messageReceived", function ($params, $user){

    return ChatApi::messageReceived($params, $user);
});

//获取用户IP
Cloud::define("getMeta", function ($params, $user, $meta){
    return array("remoteAddress" => $meta["remoteAddress"]);
});

//更新对象
Cloud::define("updateObject", function ($params, $user){
    $obj = $params["object"];
//    $obj->set("__testKey", 42);
    return $obj;
});


//登录
Cloud::onLogin(function ($user){
    error_log("Logging a user");
    return;
});

Cloud::onInsight(function ($job){
    return;
});



$engine = new LeanEngine();
$engine->start();





?>